package hirt;

/**
 * Role typically specifies the department of an item or entity in the hirt
 * simulator. A player can have many roles, as one can perform and control
 * similarly role based items. For instance, a player can have the role of
 * a fire fighter. As a result, that player controls and is responsible for
 * the fire trucks in the scenario. Roles are differentiated by a unique
 * id (per server and this class).
 * @author zamille
 */
public class Role
{
    /**
     * Numerical identification of this role, 'role id.'
     */
    int id;

    /**
     * Role type id's.
     */
    public static final int NONE    = -1;
    public static final int EMS     = 0;
    public static final int FIRE    = 1;
    public static final int POLICE  = 2;
    public static final int IDOT    = 3;
    public static final int TOW     = 4;
    public static final int VICTIM  = 5;

    /**
     * Role names by role id index.
     */
    static final String [] ROLE_NAMES =
    {
        "EMS",
        "Firefighter",
        "Police",
        "Service Patrol",
        "Towing",
        "Victim",
    };

    /**
     * Vehicle names based on role id index.
     */
    static final String [] ROLE_VEHICLE_NAMES =
    {
        "Ambulance",
        "Fire Truck",
        "Police Car",
        "Service Patrol Car",
        "Tow Truck",
        "Victim Car",
    };

    /**
     * Current number of possible roles.
     */
    public static final int NUMBER_OF_ROLES = ROLE_NAMES.length;

    /**
     * Constructor for role specified by role id.
     * @param newRoleId the id to make this new role.
     */
    public Role(int newRoleId)
    {
        changeId(newRoleId);
    }

    /**
     * Change the current role id to another.
     * @param roleId new role id for this role id.
     * @return returns whether the change was successful.
     */
    public boolean changeId(int roleId)
    {
        if (validId(roleId))
        {
            id = roleId;
             return true;
        }
        else
            return false;
    }

    /**
     * Determine if this role is current and valid.
     * @param myRole specified role id.
     * @return whether this is valid.
     */
    public static Boolean validId(int myRole)
    {
        if (myRole < NUMBER_OF_ROLES && myRole >=0)
            return true;
        else
            return false;
    }

    public int getId()
    {
        return id;
    }

    public String getName()
    {
        return( getName( id ) );
    }

    public static String getName( int roleIndex )
    {
        if( ( roleIndex >= ROLE_NAMES.length ) || ( roleIndex < 0 ) )
        {
            return( "" );
        }
        else
        {
            return( ROLE_NAMES[roleIndex] );
        }
    }

    /**
     * Get String representation of role specified by a role id.
     * @param id specified role id.
     * @return string representation of this role id.
     */
    public static String getRoleName(int id)
    {
        if (Role.validId(id))
            return getName( id );
        else
            return "";
    }

    /**
     * Get String of vehicle associated with the specified role id.
     * (Good thing it is currently a one to one situation!)
     * @param id specified role id.
     * @return string representation/name of the vehicle associated with id.
     */
    public static String getRoleVehicleName( int id )
    {
        if( ( id >= ROLE_VEHICLE_NAMES.length ) || ( id < 0 ) )
        {
            return( "" );
        }
        else
        {
            return( ROLE_VEHICLE_NAMES[id] );
        }
    }

    public byte toByte()
    {
        return (byte)id;
    }

}

